package com.ywq.wechatordersys.exception;


import com.ywq.wechatordersys.VO.Result;
import com.ywq.wechatordersys.constant.ErrorCode;
import com.ywq.wechatordersys.utils.ResultUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionHandler {
    @org.springframework.web.bind.annotation.ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handle(Exception e) {

        if (e instanceof MyException) {
            MyException exception = (MyException) e;
            return ResultUtils.fail(exception.getCode(), exception.getMessage());

        } else {
            return ResultUtils.fail(ErrorCode.UNKNOWN, e.getMessage());

        }


    }

}
